import { createStore } from 'vuex'


const store = createStore({
    state:{//存放状态
        tabbar:1,
		nav_address:{
			provinces:{name:"北京市"},
			city:{name:"北京市"},
			area:{name:"朝阳区"}
		},
		find_car_tab:1,
		log_tab:1,
		work_id:0,
		agreement:{},
		userInfo:null,
		is_login:1,
		provinces:[],
		city:[],
		area:[],
		gasoline:[],
		send_car_mode:[],
		nav_keywords:"",
		work_info:"",
		order_address:{},
		goods_info:"",
		brand_list:[],
		pay_type_list:[],
		ready_stroe:null,
		shop_order:null,
		open_config:false,
		car_data:{},
		car_goods:[],
		join_page_json:"",
		page_tab_info:"",
		second_car_info:"",
		second_choose_info:{},
		show_live:1,
		public_config:{},
		goods_keywords:"",
		search_keywords:"",
		args:"",
		live_tab:1,
		isupload:0,
		open_upload:0,
		showNotice:false
    },
	mutations:{
		changeshowNotice(state,data){
			state.showNotice = data
		},
		changeOpenUpload(state,data){
			state.open_upload = data
		},
		changeUpLoad(state,data){
			state.isupload = data
		},
		changeLiveTab(state,data){
			state.live_tab = data
		},
		changeargs(state,data){
			state.args = data
		},
		changeSearchKeyWords(state,data){
			state.search_keywords = data
		},
		changeGoodsKeyWrods(state,data){
			state.goods_keywords = data
		},
		changePublicConfig(state,data){
			state.public_config = data
		},
		changeSecondChooseInfo(state,data){
			state.second_choose_info = data
		},
		changeSecondCarInfo(state,data){
			state.second_car_info = data
		},
		changePageTabInfo(state,data){
			state.page_tab_info = data
		},
		changePageJson(state,data){
			console.log(data)
			state.join_page_json = data
		},
		changeCarGoods(state,data){
			state.car_goods = data
		},
		changeCarData(state,data){
			state.car_data = data
		},
		changeOpenConfig(state,data){
			state.open_config = !state.open_config
		},
		changeShopOrder(state,data){
			state.shop_order = data
		},
		changeReadyStore(state,data){
			console.log(data)
			state.ready_stroe = data
		},
		changePayTypeList(state,data){
			state.pay_type_list = data
		},
		changeBrandList(state,data){
			state.brand_list = data
		},
		changeGoodsInfo(state,data){
			state.goods_info = data
		},
		changeOrderAddress(state,data){
			state.order_address = data
		},
		changeWorkInfo(state,data){
			let item = JSON.stringify(data)
			state.work_info = item
		},
		changeNavKeyWords(state,data){
			console.log(data)
			state.nav_keywords = data
		},
		changeSendCarMode(state,data){
			state.send_car_mode = data
		},
		changeGasonline(state,data){
			state.gasoline = data
		},
		changeProvinces(state,data){
			state.provinces = data
		},
		changeCity(state,data){
			state.city = data
		},
		changeArea(state,data){
			state.area = data
		},
		changeUserInfo(state,data){
			state.userInfo = data
		},
		changeAgreement(state,data){
			state.agreement = data
		},
		changeWorkTab(state,data){
			state.work_id = data
		},
		changeFindCarTab(state,data){
			state.find_car_tab = data
		},
		changeLogTab(state,data){
			state.log_tab = data
		},
		changetabbar(state,data){
			state.tabbar = data
		},
		changenav_address(state,data){
			state.nav_address = data
		},
		changeLogin(state,data = 0){
			if(state.is_login === 1){
				console.log(data,"fasssss")
				state.is_login++
				uni.clearStorageSync()
				uni.clearStorage()
				// let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
				// console.log(routes)
				// let currentPage = routes[routes.length - 1].route;
				
				// if (currentPage != 'pages/login/index') {
				console.log(state.is_login,"fasssss")
				uni.reLaunch({
					url:'/pages/login/index',
					fail(e){
						console.log(e,"fasssss")
					}
				})
				// }
				
			}else{
				if(data !== 0){
					state.is_login = data
				}else{
					state.is_login++
				}
			}
		}
	},
	getters:{
		agreement(state){
			return state.agreement
		},
		gasoline(state){
			return state.gasoline
		},
		userInfo(state){
			return state.userInfo
		},
		fondCarTab(state){
			return state.find_car_tab
		},
		logTab(state){
			return state.log_tab
		},
		workTab(state){
			return state.work_id
		},
		tabCurrent(state){
			return state.tabbar
		},
		navAddress(state){
			return state.nav_address
		},
		addressList(state){
			return [state.provinces,state.city,state.area]
		}
	}
	
})

export default store